﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CompactFramework.Utilities.Localization;

namespace TripLOAMobile
{
    public partial class ShowFeedbacks : LocalizedForm
    {
        #region Initialization
        /// <summary>
        /// Initializes a new instance of the ShowFeedbacks class.
        /// </summary>
        /// <param name="f">The feedbacks.</param>
        /// <param name="avatar">The avatar.</param>
        /// <param name="nickname">The nickname.</param>
        public ShowFeedbacks(WS_SoapLogin.Feedback[] f, Image avatar, string nickname)
        {
            InitializeComponent();
            this.AddMenusToDictionary();
            UpdateResources();
            decimal general = 0;
            decimal punctuality = 0;
            decimal reliability = 0;
            decimal courtesy = 0;
            pictureBox1.Image = avatar;
            fldNickname.Text = nickname;
            fldGeneral.Text += ResourceManager.Instance.GetString("ShowFeedbacks_General")+"\r\n";
            fldDriver.Text += ResourceManager.Instance.GetString("ShowFeedbacks_Other") + "\r\n";
            fldPassenger.Text += ResourceManager.Instance.GetString("ShowFeedbacks_Other")+"\r\n";
            foreach (WS_SoapLogin.Feedback feed in f)
            {
                general += feed.generalVote;
                punctuality += feed.punctualityVote;
                reliability += feed.reliabilityVote;
                courtesy += feed.courtesyVote;
                fldGeneral.Text += "" + feed.senderNickname + " - " + feed.commentLeft + " - " + feed.generalVote.ToString() + "\r\n";
                if (feed.feedbackType)
                    fldDriver.Text += "" + feed.senderNickname + " - " + feed.punctualityVote.ToString() + " - " + feed.reliabilityVote.ToString() + " - " + feed.courtesyVote.ToString() + "\r\n";
                else fldPassenger.Text += "" + feed.senderNickname + " - " + feed.punctualityVote.ToString() + " - " + feed.reliabilityVote.ToString() + " - " + feed.courtesyVote.ToString() + "\r\n";               
            }
            if (f.Length != 0)
            {
                fldGeneralVote.Text = (general / f.Length).ToString();
                fldPunctualityVote.Text = (punctuality / f.Length).ToString();
                fldReliabilityVote.Text = (reliability / f.Length).ToString();
                fldCourtesyVote.Text = (courtesy / f.Length).ToString();
            }
            this.fldGeneral.ScrollBars = ScrollBars.Vertical;
            this.fldDriver.ScrollBars = ScrollBars.Vertical;
            this.fldPassenger.ScrollBars = ScrollBars.Vertical;
        }

        /// <summary>
        /// The subclasses of the LocalizedForm should override this method and use this method to
        /// associate all menu items with custom names with the help of AddMenuToDictionary
        /// method.
        /// </summary>
        protected override void AddMenusToDictionary()
        {
            this.AddMenuToDictionary(this.menuLeft, "menuLeft");
            this.AddMenuToDictionary(this.menuItem1, "menuBack");
            this.AddMenuToDictionary(this.menuItem2, "menuHome");
        }
        #endregion

        #region Painting
        /// <summary>
        /// Handles the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //Added to prevent painting of "ok" button
            WinAPI.ShowDoneButton(this.Handle, false);
            base.OnPaint(e);            
        }

        /// <summary>
        /// Handles the Paint event of the tabGeneral control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The PaintEventArgs instance containing the event data.</param>
        private void tabGeneral_Paint(object sender, PaintEventArgs e)
        {
            using (Graphics g = e.Graphics)
            {
                g.DrawImage(Properties.Resources.circles, 3, AutoScrollPosition.Y + 3);
                Point[] p = new Point[]{
                    new Point(40,AutoScrollPosition.Y + 25), 
                    new Point(195,AutoScrollPosition.Y + 25), 
                    new Point(190,AutoScrollPosition.Y + 30), 
                    new Point(40,AutoScrollPosition.Y + 30)};
                using (Brush b = new SolidBrush(Color.Green))
                    g.FillPolygon(b, p);

                p[0].Y = p[1].Y = AutoScrollPosition.Y + 30;
                p[2].Y = p[3].Y = AutoScrollPosition.Y + 35;
                p[1].X -= 10;
                p[2].X -= 10;
                using (Brush b = new SolidBrush(Color.GreenYellow))
                    g.FillPolygon(b, p);
            }
        }

        /// <summary>
        /// Handles the Paint event of the tabDriver control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The PaintEventArgs instance containing the event data.</param>
        private void tabDriver_Paint(object sender, PaintEventArgs e)
        {
            using (Graphics g = e.Graphics)
            {
                g.DrawImage(Properties.Resources.circles, 3, AutoScrollPosition.Y + 3);
                Point[] p = new Point[]{
                    new Point(40,AutoScrollPosition.Y + 25), 
                    new Point(195,AutoScrollPosition.Y + 25), 
                    new Point(190,AutoScrollPosition.Y + 30), 
                    new Point(40,AutoScrollPosition.Y + 30)};
                using (Brush b = new SolidBrush(Color.Green))
                    g.FillPolygon(b, p);

                p[0].Y = p[1].Y = AutoScrollPosition.Y + 30;
                p[2].Y = p[3].Y = AutoScrollPosition.Y + 35;
                p[1].X -= 10;
                p[2].X -= 10;
                using (Brush b = new SolidBrush(Color.GreenYellow))
                    g.FillPolygon(b, p);
            }
        }

        /// <summary>
        /// Handles the Paint event of the tabPassenger control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The PaintEventArgs instance containing the event data.</param>
        private void tabPassenger_Paint(object sender, PaintEventArgs e)
        {
            using (Graphics g = e.Graphics)
            {
                g.DrawImage(Properties.Resources.circles, 3, AutoScrollPosition.Y + 3);
                Point[] p = new Point[]{
                    new Point(40,AutoScrollPosition.Y + 25), 
                    new Point(195,AutoScrollPosition.Y + 25), 
                    new Point(190,AutoScrollPosition.Y + 30), 
                    new Point(40,AutoScrollPosition.Y + 30)};
                using (Brush b = new SolidBrush(Color.Green))
                    g.FillPolygon(b, p);

                p[0].Y = p[1].Y = AutoScrollPosition.Y + 30;
                p[2].Y = p[3].Y = AutoScrollPosition.Y + 35;
                p[1].X -= 10;
                p[2].X -= 10;
                using (Brush b = new SolidBrush(Color.GreenYellow))
                    g.FillPolygon(b, p);
            }
        }
        #endregion

        /// <summary>
        /// Handles the Click event of the menuItem1(back) control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The EventArgs instance containing the event data.</param>
        private void menuItem1_Click(object sender, EventArgs e)
        {
            Welcome.formBuffer.Close();
        }

        /// <summary>
        /// Handles the Click event of the menuItem2(back to home) control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The EventArgs instance containing the event data.</param>
        private void menuItem2_Click(object sender, EventArgs e)
        {
            Welcome.formBuffer.Clear();
        }
    }
}